package com.zhaojiu.example.service.beetl.function;

import org.beetl.core.Context;
import org.beetl.core.Function;

/**
 * @author huangshb
 * @date 2024/8/5
 */
public class PathToResourceName implements Function {
    @Override
    public Object call(Object[] paras, Context ctx) {
        Object o = paras[0];
        if (o != null) {
            String path = o.toString();
            if (path.startsWith("/")){
                path = path.substring(1);
            }
            path = path.replaceAll("/", "_");

            return path;
        }
        return "";
    }

    public static void main(String[] args)
    {
        PathToResourceName fn = new PathToResourceName();
        Context ctx = new Context();

        System.out.println(fn.call(new Object[]
                { "/test/my/hello/world" }, ctx));

    }

}
